/**
 * Created With IntelliJ IDEA
 * Description:牛客网：BM28 二叉树的最大深度
 * <a href="https://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73?tpId=295&tqId=642&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj">...</a>
 * User: DELL
 * Data: 2022-11-26
 * Time: 23:23
 */
import java.util.*;

class TreeNode {
      int val = 0;
      TreeNode left = null;
      TreeNode right = null;
 }

public class Solution {
    public int maxDepth (TreeNode root) {
        //空节点的深度为0
        if (root == null) {
            return 0;
        }
        //返回子树深度+1
        return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
    }
}